package com.cloud.form.api.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.cloud.form.api.entity.FormDef;
import com.cloud.form.common.utils.BaseMapperHelper;

public interface FormDefMapper extends BaseMapperHelper<FormDef> {

	@Select("select form_id, form_name from form_def where proc_def_id = #{procDefId} and valid_flag = 1 order by display_order")
	@Results({ @Result(property = "formId", column = "form_id", javaType = Long.class),
			@Result(property = "formName", column = "form_name", javaType = String.class) })
	List<FormDef> listFormByProc(@Param("procDefId") long procDefId);

	@Select("select t1.form_id, t1.form_name, t1.group_name from form_def t1 where valid_flag = 1 and exists (select * from form_input_auth t2 where t1.form_id = t2.form_id and t2.act_def_id = ${actDefId} and t2.part_id in (${parts}) and auth_code = 1)")
	@Results({ @Result(property = "formId", column = "form_id", javaType = Long.class),
			@Result(property = "formName", column = "form_name", javaType = String.class),
			@Result(property = "groupName", column = "group_name", javaType = String.class) })
	List<FormDef> ListFormByActPart(@Param("actDefId") long actDefId, @Param("parts") String parts);

}